package com.mock.action.contact;

import java.util.ArrayList;
import java.util.List;

import com.mock.dao.ContactDao;
import com.mock.dao.impl.ContactDaoImpl;
import com.mock.model.Contact;
import com.opensymphony.xwork2.ActionSupport;

public class LookUpContactAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ContactDao contactDao = new ContactDaoImpl();
	private List<ArrayList<String>> contactJson = new ArrayList<ArrayList<String>>();

	@Override
	public String execute() throws Exception {			
		return SUCCESS;
	}
	
	public String lookUpContact() {
		List<Contact> contacts = contactDao.getAllContact();
		for (Contact contact : contacts) {
			ArrayList<String> newArray = new ArrayList<String>();
			newArray.add(Long.toString(contact.getId()));
			newArray.add(contact.getFirstname() + " " + contact.getSurname());
			newArray.add(contact.getMobilePhone());
			newArray.add(contact.getEmail());
			newArray.add(contact.getContactType().getType());
			if (contact.isActive()) {
				newArray.add("Yes");				
			} else {				
				newArray.add("No");				
			}
			newArray.add(contact.getFirstname());
			newArray.add(contact.getSurname());
			contactJson.add(newArray);
		}
		return SUCCESS;
	}

	public List<ArrayList<String>> getContactJson() {
		return contactJson;
	}

	public void setContactJson(List<ArrayList<String>> contactJson) {
		this.contactJson = contactJson;
	}
	
}
